CMAKE_MINIMUM_REQUIRED(VERSION 3.20)

project(miaw VERSION 0.2)

# Being able to include modules from cmake directory
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

enable_language(CXX)
# Using C++ 20 feature set
if(WIN32)
    set(CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS} /std:c++latest /Zc:char8_t-")
else()
    set(CMAKE_CXX_STANDARD 20)
    # Disable stupid C++20 feature
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-char8_t")
    # Enable concepts
    set(CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS} -fconcepts")
    set(CMAKE_CXX_STANDARD_REQUIRED True)
endif()

try_compile(TRY_COMPILE_IDLE ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/cmake/idle.cpp)

add_executable(engine)

##########################
#   External libraries   #
##########################
#  Vulkan
find_package(Vulkan REQUIRED FATAL_ERROR)
include_directories(${Vulkan_INCLUDE_DIR})
link_libraries(${Vulkan_LIBRARY})
list(APPEND EXTERNAL_LIBRARIES ${Vulkan_LIBRARY})
# using glfw3 for window creation
find_package(glfw3 REQUIRED)
list(APPEND EXTERNAL_LIBRARIES glfw3)
# using glm for simple linear algebra
find_package(glm REQUIRED)
list(APPEND EXTERNAL_LIBRARIES glm)
# popular json library
# find_package(nlohmann REQUIRED)
# list(APPEND EXTERNAL_LIBRARIES json)
# imgui for engine editor UI
find_package(imgui CONFIG REQUIRED)
list(APPEND EXTERNAL_LIBRARIES imgui)
# tinyxml2 for data storing
find_package(tinyxml2 CONFIG REQUIRED)
list(APPEND EXTERNAL_LIBRARIES tinyxml2)
# stb
find_path(STB_INCLUDE_DIRS "stb.h")
target_include_directories(engine PRIVATE ${STB_INCLUDE_DIRS})
# tiny-obj-loader
find_package(tinyobjloader CONFIG REQUIRED)
target_link_libraries(engine PRIVATE tinyobjloader::tinyobjloader)

##########################
#    Engine Sources      #
##########################

include_directories(include)
target_link_libraries(engine PUBLIC ${EXTERNAL_LIBRARIES})
set(ENGINE_SOURCES
        src/main.cpp #  Entry
)
target_sources(engine PRIVATE ${ENGINE_SOURCES})

##########################
#   Scripts & Shaders    #
##########################

# add_subdirectory(scripts)
# add_subdirectory(shaders)

###########################
#   Compile-time Assets   #
###########################

add_subdirectory(assets)